package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import com.greensock.*;

    public class IntroShell extends Sprite
    {
        var fadeSpeed:Number;
        var fsField:TextField;
        var slideshow:Slideshow;
        var fsBtn:Sprite;
        var fieldFormat:TextFormat;
        var eField:TextField;
        var eIcon:Sprite;
        var myRoot:MovieClip;
        var eBtn:Sprite;
        var logo:Object;
        private var theXML:XMLList;
        var fsIcon:Sprite;

        public function IntroShell(param1:MovieClip, param2:Number) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            buildBtns();
            logo = new Bitmap(new Logo(0, 0));
            logo.alpha = 0;
            addChild(logo);
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        function fsRollOut(event:MouseEvent) : void
        {
            TweenMax.to(fsField, fadeSpeed, {tint:myRoot.coldColor, alpha:1, overwrite:true});
            TweenMax.to(fsIcon, fadeSpeed, {tint:myRoot.coldColor, alpha:1, overwrite:true});
            return;
        }

        public function set myXMLList(param1:XMLList) : void
        {
            theXML = param1;
            return;
        }

        function fadeOutShell() : void
        {
            fsBtn.mouseEnabled = false;
            eBtn.mouseEnabled = false;
            slideshow.stopTween();
            this.blendMode = BlendMode.LAYER;
            TweenMax.to(this, fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                dispatchEvent(new FadeOutEvent());
                return;
            }
            });
            return;
        }

        function eClick(event:MouseEvent) : void
        {
            fadeOutShell();
            return;
        }

        function buildBtns() : void
        {
            var _loc_1:* = undefined;
            fsBtn = new Sprite();
            fsBtn.useHandCursor = true;
            fsBtn.mouseEnabled = true;
            fsBtn.buttonMode = true;
            fsBtn.mouseChildren = false;
            fsBtn.addEventListener(MouseEvent.MOUSE_OVER, fsRollOver, false, 0, true);
            fsBtn.addEventListener(MouseEvent.MOUSE_OUT, fsRollOut, false, 0, true);
            fsBtn.addEventListener(MouseEvent.CLICK, fsClick, false, 0, true);
            fsField = new TextField();
            _loc_1 = new TextFormat();
            _loc_1.font = new HelveticaLightEmbed().fontName;
            _loc_1.size = 14;
            _loc_1.letterSpacing = 0;
            _loc_1.leftMargin = 0;
            _loc_1.rightMargin = 0;
            _loc_1.color = myRoot.coldColor;
            fsField.name = "fsField";
            fsField.autoSize = "left";
            fsField.antiAliasType = AntiAliasType.ADVANCED;
            fsField.gridFitType = GridFitType.SUBPIXEL;
            fsField.selectable = false;
            fsField.embedFonts = true;
            fsField.text = "Enter Fullscreen";
            fsField.setTextFormat(_loc_1);
            fsField.x = -3;
            fsBtn.graphics.beginFill(16777215, 0);
            fsBtn.graphics.drawRect(0, -10, fsField.width + 20, fsField.height + 20);
            fsBtn.graphics.endFill();
            fsIcon = new Sprite();
            fsIcon.graphics.beginFill(7829367, 0.5);
            fsIcon.graphics.drawRect(0, 0, 17, 1);
            fsIcon.graphics.drawRect(0, 1, 1, 12);
            fsIcon.graphics.drawRect(16, 1, 1, 12);
            fsIcon.graphics.drawRect(1, 12, 15, 1);
            fsIcon.graphics.endFill();
            fsIcon.graphics.beginFill(7829367, 1);
            fsIcon.graphics.drawRect(2, 2, 13, 1);
            fsIcon.graphics.drawRect(2, 3, 1, 8);
            fsIcon.graphics.drawRect(14, 3, 1, 8);
            fsIcon.graphics.drawRect(3, 10, 11, 1);
            fsIcon.graphics.endFill();
            fsIcon.alpha = 1;
            fsBtn.addChild(fsIcon);
            fsBtn.alpha = 0;
            fsBtn.addChild(fsField);
            eBtn = new Sprite();
            eBtn.useHandCursor = true;
            eBtn.mouseEnabled = true;
            eBtn.buttonMode = true;
            eBtn.mouseChildren = false;
            eBtn.addEventListener(MouseEvent.MOUSE_OVER, eRollOver, false, 0, true);
            eBtn.addEventListener(MouseEvent.MOUSE_OUT, eRollOut, false, 0, true);
            eBtn.addEventListener(MouseEvent.CLICK, eClick, false, 0, true);
            eField = new TextField();
            eField.name = "eField";
            eField.autoSize = "left";
            eField.antiAliasType = AntiAliasType.ADVANCED;
            eField.gridFitType = GridFitType.SUBPIXEL;
            eField.selectable = false;
            eField.embedFonts = true;
            eField.text = "Enter Standard";
            eField.setTextFormat(_loc_1);
            eField.x = -3;
            eBtn.graphics.beginFill(16777215, 0);
            eBtn.graphics.drawRect(0, -10, eField.width + 50, eField.height + 20);
            eBtn.graphics.endFill();
            eIcon = new Sprite();
            eIcon.graphics.beginFill(7829367, 0.5);
            eIcon.graphics.drawRect(0, 0, 17, 1);
            eIcon.graphics.drawRect(0, 1, 1, 12);
            eIcon.graphics.drawRect(16, 1, 1, 12);
            eIcon.graphics.drawRect(1, 12, 15, 1);
            eIcon.graphics.endFill();
            eIcon.graphics.beginFill(7829367, 1);
            eIcon.graphics.drawRect(4, 3, 9, 1);
            eIcon.graphics.drawRect(4, 4, 1, 6);
            eIcon.graphics.drawRect(12, 4, 1, 6);
            eIcon.graphics.drawRect(5, 9, 7, 1);
            eIcon.graphics.endFill();
            eIcon.alpha = 1;
            eBtn.addChild(eIcon);
            eField.alpha = 0;
            eBtn.addChild(eField);
            return;
        }

        function doResize() : void
        {
            var _loc_1:* = myRoot.unitW / 75;
            logo.scaleX = myRoot.unitW / 75;
            logo.scaleY = _loc_1;
            if (logo.scaleY < 1)
            {
                logo.smoothing = true;
            }
            else
            {
                logo.smoothing = false;
            }
            logo.x = Math.round(myRoot.gridX + (12 * myRoot.unitW + 11 * myRoot.gutterW - logo.width) / 2);
            logo.y = Math.round(myRoot.gridY + (myRoot.headerH + 3 * (myRoot.unitH + myRoot.gutterH) - 5 / 9 * myRoot.gutterH - logo.height));
            if (fsBtn != null)
            {
                eBtn.x = myRoot.gridX;
                eBtn.y = Math.round(myRoot.gridY + myRoot.gridCurrH);
                var _loc_1:* = myRoot.unitW / 75;
                eField.scaleY = myRoot.unitW / 75;
                eField.scaleX = _loc_1;
                eIcon.x = Math.round(eField.width);
                eIcon.y = Math.round(myRoot.gutterH + myRoot.gutterH - eIcon.height);
                fsBtn.x = Math.round(myRoot.gridX + 2 * (myRoot.unitW + myRoot.gutterW));
                fsBtn.y = Math.round(myRoot.gridY + myRoot.gridCurrH);
                var _loc_1:* = eField.scaleX;
                fsField.scaleY = eField.scaleX;
                fsField.scaleX = _loc_1;
                fsIcon.x = Math.round(fsField.width);
                fsIcon.y = Math.round(myRoot.gutterH + myRoot.gutterH - eIcon.height);
            }
            if (slideshow != null && slideshow.init == true)
            {
                slideshow.x = myRoot.gridX;
                slideshow.y = myRoot.gridY;
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        public function buildSlideshow() : void
        {
            slideshow = new Slideshow(myRoot, theXML, fadeSpeed);
            slideshow.addEventListener(SlideshowInitEvent.INIT_COMPLETE, slideshowInit, false, 0, true);
            slideshow.buttonMode = true;
            slideshow.addEventListener(MouseEvent.MOUSE_OVER, eRollOver, false, 0, true);
            slideshow.addEventListener(MouseEvent.MOUSE_OUT, eRollOut, false, 0, true);
            slideshow.addEventListener(MouseEvent.CLICK, eClick, false, 0, true);
            addChild(slideshow);
            addChild(logo);
            return;
        }

        function eRollOver(event:MouseEvent) : void
        {
            TweenMax.to(eField, fadeSpeed, {tint:myRoot.hotColor, alpha:1, overwrite:true});
            TweenMax.to(eIcon, fadeSpeed, {tint:myRoot.hotColor, alpha:1, overwrite:true});
            return;
        }

        function eRollOut(event:MouseEvent) : void
        {
            TweenMax.to(eField, fadeSpeed, {tint:myRoot.coldColor, alpha:1, overwrite:true});
            TweenMax.to(eIcon, fadeSpeed, {tint:myRoot.coldColor, alpha:1, overwrite:true});
            return;
        }

        function slideshowInit(event:SlideshowInitEvent) : void
        {
            doResize();
            TweenMax.to(logo, fadeSpeed * 4, {alpha:1, overwrite:true});
            return;
        }

        function fsClick(event:MouseEvent) : void
        {
            visible = false;
            fadeOutShell();
            myRoot.openFullscreen();
            return;
        }

        function fsRollOver(event:MouseEvent) : void
        {
            TweenMax.to(fsField, fadeSpeed, {tint:myRoot.hotColor, alpha:1, overwrite:true});
            TweenMax.to(fsIcon, fadeSpeed, {tint:myRoot.hotColor, alpha:1, overwrite:true});
            return;
        }

        public function fadeInBtns() : void
        {
            addChild(fsBtn);
            TweenMax.to(fsBtn, fadeSpeed, {alpha:1, overwrite:true});
            addChild(eBtn);
            TweenMax.to(eField, fadeSpeed, {alpha:1, overwrite:true});
            return;
        }

    }
}
